package com.dyna.mapper;

import com.dyna.core.LambdaQueryWrapperX;
import com.dyna.domain.resp.PageResult;
import com.dyna.foundation.domain.entity.SysTenant;
import com.dyna.foundation.domain.req.SysTenantPageReq;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SysTenantMapper extends BaseMapperX<SysTenant> {

    default PageResult<SysTenant> selectPage(SysTenantPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysTenant>()
                .likeIfPresent(SysTenant::getName, reqVO.getName())
                .likeIfPresent(SysTenant::getContactName, reqVO.getContactName())
                .likeIfPresent(SysTenant::getContactMobile, reqVO.getContactMobile())
                .eqIfPresent(SysTenant::getStatus, reqVO.getStatus())
                .betweenIfPresent(SysTenant::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SysTenant::getId));
    }

    default SysTenant selectByName(String name) {
        return selectOne(SysTenant::getName, name);
    }

    default SysTenant selectByWebsite(String website) {
        return selectOne(SysTenant::getWebsite, website);
    }

    default List<SysTenant> selectListByPackageId(Long packageId) {
        return selectList(SysTenant::getPackageId, packageId);
    }

    default Long selectCountByPackageId(Long packageId) {
        return selectCount(SysTenant::getPackageId, packageId);
    }

}